package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.service.ItemCatService;
import com.dongdongshop.vo.ItemCatVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("itemCat")
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;

    @PostMapping("getAllItem")
    public Result getAllItem(@RequestParam Long parentId) {
        List<ItemCatVO> itemCatVOS = itemCatService.getAllItem(parentId);
        return Result.OK().setData(itemCatVOS);
    }

    @PostMapping("addItemCat")
    public Result addItemCat(@RequestBody ItemCatVO itemCatVO) {
        itemCatService.addItemCat(itemCatVO);
        return Result.OK();
    }

    @GetMapping("getItemById")
    public Result getItemById(@RequestParam Long id) {
        ItemCatVO itemCatVO = itemCatService.getItemById(id);
        return Result.OK().setData(itemCatVO);
    }


    @PostMapping("updateItemCat")
    public Result updateItemCat(@RequestBody ItemCatVO itemCatVO) {
        itemCatService.updateItemCat(itemCatVO);
        return Result.OK();
    }

    @PostMapping("deleteBatch")
    public Result deleteBatch(@RequestBody List<Long> ids) {
        itemCatService.deleteBatch(ids);
        return Result.OK();
    }
}
